// 输入：l1 = [2, 4, 3], l2 = [5, 6, 4]
// 输出：[7, 0, 8]
// 解释：342 + 465 = 807.

// 输入：l1 = [9, 9, 9, 9, 9, 9, 9], l2 = [9, 9, 9, 9]
// 输出：[8, 9, 9, 9, 0, 0, 0, 1]

let l1 = [9, 9, 9, 9, 9, 9, 9], l2 = [9, 9, 9, 9]
var addTwoNumbers = function (l1, l2) {
    let alen = l1.length
    let blen = l2.length
    while (alen > blen) {
        l2.push(0)
        blen++
    }
    while (blen > alen) {
        l1.push(0)
        alen++
    }
    let ListNode = []
    let jinwei = 0
    for (let i = 0; i < alen; i++) {
        let sum = l1[i] + l2[i] + jinwei
        if (sum < 10) {
            ListNode.push(sum)
            jinwei = 0
        } else {
            ListNode.push(sum % 10)
            jinwei = 1
        }
    }

    if (jinwei) {
        ListNode.push(jinwei)
    }

    return ListNode
};

console.log(addTwoNumbers(l1, l2));
